package com.zjt.smart.ui.adapter.base;

import android.content.Context;

import java.util.List;

public abstract class TypeAdapter extends BaseAdapter<BaseAdapter.BaseHolder, Object> {

    public TypeAdapter(Context mContext) {
        super(mContext);
    }

    public TypeAdapter(Context mContext, List<Object> mListData) {
        super(mContext, mListData);
    }

    @Override
    public void addAll(List<Object> newData) {
        super.addAll(serializeList(newData));
    }

    @Override
    public int getItemViewType(int position) {
        if (position == getItemCount() - 1) {
            return ITEM_TYPE_FOOTER;
        }else {
            return getItemType(position);

        }
    }

    public int getSpanCount(int position) {
        return 1;
    }

    public abstract int getItemType(int position);

    protected abstract List<Object> serializeList(List list);

    public boolean hasTypeData(int type){
        if (mListData == null){
            return false;
        }
        for (int i = 0; i < mListData.size(); i++) {
            int t = getItemType(i);
            if (t == type){
                return true;
            }
        }
        return false;
    }
}
